package cn.tedu.zhwy.information.controller;

import cn.tedu.zhwy.base.response.JsonResult;
import cn.tedu.zhwy.information.pojo.dto.BuildingQuery;
import cn.tedu.zhwy.information.pojo.dto.BuildingSaveParam;
import cn.tedu.zhwy.information.pojo.vo.BuildingVO;
import cn.tedu.zhwy.information.service.BuildingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/v1/building/")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;

    @PostMapping("save")
    public JsonResult saveBuilding(BuildingSaveParam buildingSaveParam){
        log.debug("新增楼座:buildingSaveParam={}",buildingSaveParam);
        buildingService.saveBuilding(buildingSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult selectBuilding(BuildingQuery buildingQuery){
        log.debug("搜索参数:buildingQuery={}",buildingQuery);
        List<BuildingVO> list = buildingService.selectBuilding(buildingQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("delete/{bid}")
    public JsonResult deleteBuilding(@PathVariable Long bid){
        log.debug("楼座id:bId={}",bid);
        buildingService.deleteBuilding(bid);
        return JsonResult.ok();
    }
}
